package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.AlertRuleDto;
import com.zzyl.service.AlertRuleService;
import com.zzyl.vo.AlertRuleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/alert-rule")
@Slf4j
@Api(tags = "报警规则相关接口")
public class AlertRuleController {

    @Autowired
    public AlertRuleService alertRuleService;

    /**
     * 新增报警规则
     * @param alertRuleDto
     * @return
     */
    @PostMapping("/create")
    @ApiOperation("新增报警规则")
    private ResponseResult createAlertRule(@RequestBody @ApiParam("新增报警信息")AlertRuleDto alertRuleDto){
        alertRuleService.createAlertRule(alertRuleDto);
        return ResponseResult.success();
    }

    /**
     * 分页获取告警规则列表
     * @param pageNum
     * @param pageSize
     * @param alertRuleName
     * @param functionName
     * @param productKey
     * @return
     */
    @GetMapping
    @ApiOperation("分页获取告警规则列表")
    private ResponseResult<PageResponse> getPage(
            Integer pageNum,
            Integer pageSize,
            String alertRuleName,
            String functionName,
            String productKey){
        PageResponse alertRulePage = alertRuleService.getPage(pageNum,pageSize,alertRuleName,functionName,productKey);
        return ResponseResult.success(alertRulePage);
    }

    /**
     * 获取单个告警规则
     * @param id
     * @return
     */
    @ApiOperation("获取单个告警规则")
    @GetMapping("/read/{id}")
    private ResponseResult<AlertRuleVo> getAlertRuleVo(@PathVariable @ApiParam("查询id") Long id){
       return ResponseResult.success( alertRuleService.getAlertRuleVo(id));
    }

    /**
     * 更新告警规则
     * @param alertRuleDto
     * @param id
     * @return
     */
    @ApiOperation("更新告警规则")
    @PutMapping("/update/{id}")
    private ResponseResult updateAlertRuleVo(
            @RequestBody @ApiParam("更新信息") AlertRuleDto alertRuleDto,
            @PathVariable  @ApiParam("更新id") Long id){
        alertRuleService.updateAlertRuleVo(alertRuleDto,id);
        return ResponseResult.success();
    }

    /**
     * 删除告警规则
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除告警规则")
    private ResponseResult deleteAlertRuleVo(@PathVariable @ApiParam("删除id") Long id){
        alertRuleService.deleteAlertRuleVo(id);
        return ResponseResult.success();
    }

    /**
     * 启用-禁用
      * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用-禁用")
    private ResponseResult updateStatus(
            @PathVariable @ApiParam("状态id") Long id,
            @PathVariable @ApiParam("状态") Integer status){
        alertRuleService.updateStatus(id,status);
        return ResponseResult.success();
    }
}
